package com.pureut.storage.dubbo;

import com.pureut.storage.service.PurchaseReceiptService;
import com.sale.common.core.domain.R;
import com.sale.common.core.utils.BeanCopyUtils;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import com.sale.order.api.vo.PurchaseOrderTraceVo;
import com.sale.storage.api.RemotePurchaseReceiptService;
import com.sale.storage.api.dto.PurchaseOrderDto;
import com.sale.storage.api.dto.PurchaseOrderTrackDto;
import com.sale.storage.api.vo.MaterialVo;
import com.sale.storage.api.vo.UpdateInvoicedQuantityVo;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 仓库dubbo
 */
@RequiredArgsConstructor
@DubboService
@Service
public class RemotePurchaseReceiptServiceImpl implements RemotePurchaseReceiptService {

    private final PurchaseReceiptService purchaseReceiptService;


    /**
     * 采购入库新增
     *
     * @param purchaseOrderDto
     * @return
     */
    @Override
    public boolean batchArrival(PurchaseOrderDto purchaseOrderDto) throws Exception {
        com.pureut.storage.dto.PurchaseOrderDto purchaseOrderDto1 = new com.pureut.storage.dto.PurchaseOrderDto();

        purchaseOrderDto1.setSupplierCode(purchaseOrderDto.getSupplierCode());
        purchaseOrderDto1.setDrawerTime(purchaseOrderDto.getDrawerTime());
        purchaseOrderDto1.setEstimatedTime(purchaseOrderDto.getEstimatedTime());
        purchaseOrderDto1.setPurchaseContractNo(purchaseOrderDto.getPurchaseContractNo());
        purchaseOrderDto1.setPurchaseOrderNo(purchaseOrderDto.getPurchaseOrderNo());
        purchaseOrderDto1.setMaterialCategory(purchaseOrderDto.getMaterialCategory());
        List<MaterialVo> materialList = purchaseOrderDto.getMaterialList();
        List<com.pureut.storage.vo.MaterialVo> list = new ArrayList<>();
        for (MaterialVo entity : materialList) {
            com.pureut.storage.vo.MaterialVo materialVo = new com.pureut.storage.vo.MaterialVo();
            BeanUtils.copyProperties(entity, materialVo);
            list.add(materialVo);
        }
        purchaseOrderDto1.setMaterialList(list);

        return purchaseReceiptService.batchArrival(purchaseOrderDto1);
    }

    /**
     * 采购订单跟踪查询
     *
     * @return
     */
    @Override
    public List<PurchaseOrderTrackDto> purchaseOrderTrackList(PurchaseOrderTraceVo purchaseOrderTraceVo) {
        TableDataInfo<PurchaseOrderTrackDto> purchaseOrderTrackDtoTableDataInfo = purchaseReceiptService.purchaseOrderTrackList(purchaseOrderTraceVo);
        return purchaseOrderTrackDtoTableDataInfo.getRows();
    }

    /**
     * 财务模块修改采购入库、销售退货、销售发货、采购退货发票数量及核销金额
     */
    @Override
    public boolean updateInvoicedQuantity(UpdateInvoicedQuantityVo updateInvoicedQuantityVo) {
        return purchaseReceiptService.updateInvoicedQuantity(updateInvoicedQuantityVo);
    }
}
